﻿@{
    Layout = "~/Views/Shared/_LayoutMain.cshtml";
    ViewBag.Title = "网非e学院--课程详情";
    var course = ViewBag.CourseInfo as XZL.Web.Entity.Course;
    var inviteList = ViewBag.InviteList as List<XZL.Web.Entity.Course>;
    var videoList = ViewBag.VideoList as List<XZL.Web.Da.Proc_CourseItem_SelectListByCourseIDResult>;
    var commetList = ViewBag.CommetList as List<XZL.Web.Da.Proc_Comment_SelectListResult>;
    ViewBag.Description = course.CourseName;
}

<div>
    <div class="ci_Fenxiang" id="Fenxiang" onclick="HideFenxiang()">
        <img src="~/Image/bgFenxiang.png" class="ci_FenxiangImg" />
    </div>

    @if (course.VideoLink != null && course.VideoLink != "")
    {
        <video src="@course.VideoLink" controls="controls" style="width:100%;background-color:black" id="video" webkit-playsinline="true">您的浏览器不支持 video 标签。</video>
    }
    else
    {
        <div class="ci_Top">
            <img class="ci_courseImg" id="ci_courseImg" src="@course.CourseInfoImg" />
            <div class="ci_TopTextBG">
            </div>
            <div class="ci_TopText">@*<img src="~/Image/icoShiping.png" />&nbsp;&nbsp;*@@course.CourseName</div>
        </div>
    }


    <div class="ci_Function">
        <span class="ci_FunctionItem" onclick="FenXiang()">
            <img src="~/Image/icoFenxiang.png" /><br />
            分享
        </span>
        <span class="ci_FunctionItem" onclick='Collect()'>
            @if (ViewBag.IsCourse == "1")
            {
                <img id="imgCollect" src="~/Image/icoYiShoucang.png" /><br />
                <span id="txtCollect">取消收藏</span>
            }
            else
            {
                <img id="imgCollect" src="~/Image/icoShoucang.png" /><br />
                <span id="txtCollect">收藏</span>
            }
        </span>
        <span class="ci_FunctionItem" onclick="Comment()">
            <img src="~/Image/icoPingjia.png" /><br />
            评价 @ViewBag.CommentCount
        </span>
    </div>

    <div id="divInfo">
        <div class="ci_Teacher" id="ci_Teacher">
            <div class="ci_TeacherImgBG">
                <img class="ci_TeacherImg" src="@course.TeacherImg">
            </div>
            <div class="ci_TeacherInfo">
                <b style="font-size:15px">@course.TeacherName</b><br />
                @Html.Raw(course.TeacherInfo)<br /><br />
            </div>
            <div class="ci_Price">
                <b style="font-size:16px;color:#FF8800">￥@Convert.ToDouble(course.Price).ToString("0.00")</b>
            </div>
            <div class="ci_Buy">
                @*@if (ViewBag.IsBuy < 0)*@

                <div class="ci_BugButton" onclick="document.location='../../Course/BuyCourse?ID=@course.CourseID'">购买课程</div>

                @*else
                    {
                        <b class="customBtn" style="width:71px;height:27px;line-height:27px; font-size:14px;">已购买</b>
                    }*@
            </div>
            @if (course.CourseExplain == "" || course.CourseExplain == null)
            {
                <div id="courseExplain"></div>
            }
            else
            {
                <div class="ci_TeacherSM" id="courseExplain">
                    @course.CourseExplain
                </div>
            }
        </div>

        <div class="ci_TextTitle">课程章节：</div>

        <div class="ci_Course">
            @if (videoList.Count > 0)
            {
                foreach (var item in videoList)
                {
                    if (ViewBag.IsBuy < 0)
                    {
                        <div class="ci_CourseItem" onclick="ShowModal('抱歉，您未购买此课程！')">
                            <img class="ci_CourseItemImg" src="@item.Image" /><br />
                            <div class="ci_CourseItemText">
                                <b class="ci_CourseItemTitle">@item.ItemNum</b><span style="float:right">[@Convert.ToDateTime(item.StartTime).ToString("MM/dd HH:mm")]</span><br />
                                <span>@item.ItemName</span>
                            </div>
                        </div>
                    }
                    else
                    {
                        if (item.StartTime > DateTime.Now)
                        {
                            <div class="ci_CourseItem" onclick="ShowModal('未到开课时间，请您耐心等待！')">
                                <img class="ci_CourseItemImg" src="@item.Image" /><br />
                                <div class="ci_CourseItemText">
                                    <b class="ci_CourseItemTitle">@item.ItemNum</b><span style="float:right">[@Convert.ToDateTime(item.StartTime).ToString("MM/dd HH:mm")]</span><br />
                                    <span>@item.ItemName</span>
                                </div>
                            </div>
                        }
                        else if (item.StartTime.Value.AddHours(Convert.ToInt32(item.ValidTime)) < DateTime.Now)
                        {
                            <div class="ci_CourseItem" onclick="ShowModal('该课程已过期！');">
                                <img class="ci_CourseItemImg" src="@item.Image" /><br />
                                <div class="ci_CourseItemText">
                                    <b class="ci_CourseItemTitle">@item.ItemNum</b><span style="float:right">[@Convert.ToDateTime(item.StartTime).ToString("MM/dd HH:mm")]</span><br />
                                    <span>@item.ItemName</span>
                                </div>
                            </div>}
                        else
                        {
                            <div class="ci_CourseItem" onclick="document.location = '../../Course/CoursePlay/@item.ItemID'">
                                <img class="ci_CourseItemImg" src="@item.Image" /><br />
                                <div class="ci_CourseItemText">
                                    <b class="ci_CourseItemTitle">@item.ItemNum</b><span style="float:right">[@Convert.ToDateTime(item.StartTime).ToString("MM/dd HH:mm")]</span><br />
                                    <span>@item.ItemName</span>
                                </div>
                            </div>
                        }
                    }
                }
            }
            else
            {
                <div style="line-height:50px; padding:10px;">
                    暂无课程章节。
                </div>
            }
        </div>

        <div class="ci_TextTitle">课程介绍：</div>

        <div class="ci_CourseIntro" id="ci_CourseIntro">
            <div class="ci_CourseIntroTitle">学员咨询专线：010-64738501/64756681</div>
            @Html.Raw(course.CourseIntroduce)
        </div>

        @if (inviteList.Count > 0)
        {
            <div class="ci_TextTitle">更多推荐：</div>
            <div id="courseConList">
                @foreach (var item in inviteList)
                {
                    <div class="courseBG" onclick="document.location='../../Course/CourseInfo?CourseID=@item.CourseID&InviteID=@ViewBag.InviteID'">
                        <div class="courseItem">
                            <img src="@item.CourseImg" class="courseImg" />
                            <span class="courseText">
                                <span class="courseTitle">
                                    @item.CourseName
                                </span><br />
                                <span>
                                    开课时间：@item.StartTime.ToString("MM/dd HH:mm")
                                </span><br />
                                <span>
                                    @item.TeacherName | @item.TeacherTitle1
                                </span><br />
                                <span>
                                    @item.TeacherTitle2
                                </span>
                            </span>
                        </div>
                    </div>
                }
            </div>
        }
    </div>

    <div id="divComment" style="display:none">
        <div class="cm_CommentTitle">
            <textarea class="cm_CommentTitleText" placeholder="请输入课程评价" id="txtContent"></textarea>
            <span class="customBtn cm_CommentTitleBtn" id="addComment" onclick="AddComment()">评价</span>
            <span class="customBtn cm_CommentTitleBtn" style="top:38px;" onclick="ReturnInfo()">返回</span>
        </div>
        @foreach (var item in commetList)
        {
            <div class="cm_CommentItem">
                <div class="cm_CommentLeft">
                    <img class="cm_CommentImg" src="@item.HeadPortrait" />
                </div>
                <div class="cm_CommentRight">
                    <div class="cm_CommentNick">
                        <div class="cm_CommentNickText">@item.WeiXinName</div>
                        <div class="cm_CommentParise" id="@item.CommentID">
                            <img src="~/Image/logoParise.png" width="16" height="16" />&nbsp;
                        </div>
                        <div class="cm_CommentPariseNum">
                            @item.PraiseNum
                        </div>
                    </div>
                    <div class="cm_CommentContent">@item.CommentContent</div>
                    <div class="cm_CommentTime">@item.CreateTime</div>
                    @if (item.ReplyContent != null && item.ReplyContent != "")
                    {
                        <div class="cm_CommentNick">管理员回复：</div>
                        <div class="cm_CommentContent">@item.ReplyContent</div>
                        <div class="cm_CommentTime">@item.ReplyTime</div>
                    }
                </div>
            </div>
        }
    </div>
</div>
<script>
    //底部导航选中
    $("#ImgKecheng").attr("src", "../../Image/logoKechengSel.png");

    //顶部图片高度计算
    var widthScreen = $("#ci_courseImg").width()
    $("#ci_courseImg").height(widthScreen * 11 / 18);

    //视频列表高度计算
    var courseHight = ($(".ci_CourseItemImg").eq(0).width()) * 4 / 5;
    $(".ci_CourseItemImg").height(courseHight);
    $(".ci_CourseItem").height(courseHight + 65);

    //课程列表通过图片计算显示大小
    var courseHight = ($(".courseImg").eq(0).width()) * 4 / 5;
    $(".courseItem").height(courseHight);
    $(".courseImg").height(courseHight);
    $(".courseText").height(courseHight);

    //调整课程说明高度
    var explainHeight=$("#courseExplain").height();
    $("#ci_Teacher").height(explainHeight+170);

    //分享图片高度
    var heightScreen = document.body.clientHeight;
    $("#Fenxiang").height(heightScreen);

    //分享
    function FenXiang() {
        $("#Fenxiang").show();
    }
    //隐藏分享图片
    function HideFenxiang() {
        $("#Fenxiang").hide();
    }

    //收藏/取消收藏
    function Collect(){
        var courseID=@course.CourseID;
        var userID="@ViewBag.UserID";
        $.ajax({
            type: "Post", //提交方式
            url: "../../Course/CollectCourse",//获取数据的函数
            data: { "UserID": userID,"CourseID":courseID }, //参数
            error: function () {  },
            success: function (data) {
                if (data == "1") {
                    $("#imgCollect").attr("src","../../Image/icoYiShoucang.png")
                    $("#txtCollect").html("取消收藏");
                }
                else if(data=="2")
                {
                    $("#imgCollect").attr("src","../../Image/icoShoucang.png")
                    $("#txtCollect").html("收藏");
                }
            }
        });
    }

    //弹出框
    function ShowModal(info) {
        layer.alert(info, {
            extend: ['skin/orange/style.css'],
            skin: 'layui-ext-orange' //样式类名
           ,closeBtn: 0
        })
    }

    //评价页
    function Comment()
    {
        $("#divComment").show();
        $("#divInfo").hide();
    }

    //返回详情页
    function ReturnInfo()
    {
        $("#divComment").hide();
        $("#divInfo").show();
    }

    //提交评价
    function AddComment(){
        var courseID=@course.CourseID;
        var userID="@ViewBag.UserID";
        var content=$("#txtContent").val();
        if(content.length>=8){
            $.ajax({
                type: "Post",
                url: "../../Course/AddComment",
                data: { "UserID": userID,"CourseID":courseID,"Content": content},
                error: function () {  },
                success: function (data) {
                    if (data == true) {
                        ShowModal('您的评价已提交，管理员审核通过后才能显示！');
                        $("#addComment").attr("onclick","");
                        $("#txtContent").val("");
                        $("#txtContent").attr("readOnly","true");
                    }
                    else
                    {
                        ShowModal('抱歉，您的评价提交失败！');
                    }
                }
            });
        }
        else
        {
            ShowModal('请输入8-100字的课程评价！');
        }
    }

    //点赞
    $(".cm_CommentParise").click(function(){
        var userID="@ViewBag.UserID";
        var ind=$(".cm_CommentParise").index(this);
        var commentID=$(this).attr("id");
        var commentNum=$(".cm_CommentPariseNum").eq(ind).html();
        $.ajax({
            type: "Post",
            url: "../../Course/Parise",
            data: { "UserID": userID,"CommentID":commentID},
            error: function () {  },
            success: function (data) {
                if (data == 0) {
                    $(".cm_CommentPariseNum").eq(ind).html(Number(commentNum)+1);
                }
                else
                {
                    ShowModal('您已对该评论点过赞！');
                }
            }
        });
    })

</script>

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    wx.config({
        debug: false,
        appId: "@ViewBag.AppID",
        timestamp: "@ViewBag.Timestamp",
        nonceStr: "@ViewBag.NonceStr",
        signature: "@ViewBag.Sign",
        jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 功能列表，我们要使用JS-SDK的什么功能
    });

    wx.ready(function () {
        // 获取“分享到朋友圈”按钮点击状态及自定义分享内容接口
        wx.onMenuShareTimeline({
            title: '推荐 网非网络学院好课程：@course.CourseName', // 分享标题
            link: "@ViewBag.Url",
            imgUrl: "@course.CourseInfoImg", // 分享图标
        });

        // 获取“分享给朋友”按钮点击状态及自定义分享内容接口
        wx.onMenuShareAppMessage({
            title: '推荐 网非网络学院好课程：@course.CourseName', // 分享标题
            desc: "网非父母网络课堂，精彩内容等你体验", // 分享描述
            link: "@ViewBag.Url",
            imgUrl: "@course.CourseInfoImg", // 分享图标
            type: 'link', // 分享类型,music、video或link，不填默认为link
        });
        //wx.error(function (res) {
        //    alert('wx.error: ' + JSON.stringify(res));
        //});
    });
</script>
